import { createSlice } from '@reduxjs/toolkit'
import dayjs from 'dayjs'

export const ticketSlice = createSlice({
  name: 'ticket',
  initialState: {
    start:'北京',
    end:'上海',
    date:dayjs().format('YYYY-MM-DD'),
    isSpeed:false
  },
  reducers: {
    jh(state){
        let temp=state.start
        state.start=state.end 
        state.end=temp
    },
    setDate(state,actions){
        state.date=dayjs(actions.payload).format("YYYY-MM-DD")
    },
    setIsSpeed(state,actions){
        state.isSpeed=actions.payload
    },
    setCity(state,actions){
        state[actions.payload.propName]=actions.payload.city
    }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { jh,setDate,setIsSpeed,setCity } = ticketSlice.actions

export default ticketSlice.reducer